/*
 * LagSolvers.h
 *
 *  Created on: Oct 25, 2011
 *      Author: correa
 */

#ifndef LAGSOLVERS_H_
#define LAGSOLVERS_H_

#include <StabSolvers.h>

class RepLag : public RepStab {
	friend class StabSolver;

private:
	int status;
protected:
	// base solvers
	CPXLPptr *		subsolver;

	RepLag(Graph * g, Weight<double> * w);
	template <class M, class G>
	RepLag(Graph * g, ModelerFactory<M,G> * fm, Weight<double> * w);
	template <class M, class G>
	RepLag(Graph * g, ModelerFactory<M,G> * fm, Weight<double> * w, int col, const char * prefix);
	void build(int k);
public:
	virtual ~RepLag();
};

class MaxRepLag : public RepLag {
	bool				unit;
	bool				hassol;
	double				bestobj;
	void init(int k);
public:
	~MaxRepLag();
	virtual int objective();
	template <class M, class G>
	MaxRepLag(Graph * g, ModelerFactory<M,G> * fm, int k);
	template <class M, class G>
	MaxRepLag(Graph * g, ModelerFactory<M,G> * fm, Weight<double> * w, int k);
	template <class M, class G>
	MaxRepLag(Graph * g, ModelerFactory<M,G> * fm, int col, const char * prefix, int k);
	template <class M, class G>
	MaxRepLag(Graph * g, ModelerFactory<M,G> * fm, Weight<double> * w, int col, const char * prefix, int k);
	virtual int solveByEnumeration();
	virtual int getBest(double * val);
	virtual int getNodes(int * nnd);

    // Static class to create objects
    // Change is required only in this function to create a new object type
    template <class M, class G>
    static StabSolver * create(string relax, Graph * g, ModelerFactory<M,G> * fm, int k);
};

template <class M, class G>
inline StabSolver * MaxRepLag::create(string relax, Graph * g, ModelerFactory<M,G> * fm, int k) {
	if (relax == "linear" || relax == "alinear")
		return MaxRepStab::create(relax, g, fm, k);
	if (relax == "lag" || relax == "alag")
		return new MaxRepLag(g, fm, k);
	return NULL;
}


#endif /* LAGSOLVERS_H_ */
